*data_prep.do
*File imported from here on May 28, 2012: http://www.systemicpeace.org/inscr/p4v2010.xls

clear
*global filetree /Users/Allan/Dropbox/!!Papers/Liberal Peace/12-02-21_ISQ_commentary/DOR_ISQ_2013_Replication/M_Rep

cd "$filetree"

set more off
import excel "Other_files/p4v2010.xls", sheet("p4v2010") firstrow

order ccode year polity2
sort ccode year
keep ccode year polity2
rename ccode ccode1
sort ccode1 year
save "Other_files/p4v2010_1.dta", replace

rename ccode1 ccode2
sort ccode2 year
save "Other_files/p4v2010_2.dta", replace
clear

*Gleditsch Trade and GDP data
clear
*Downloaded from here: http://privatewww.essex.ac.uk/~ksg/exptradegdp.html
insheet using "Other_files/exptradegdpv4.1 2/expdata.asc", delimiter(" ")
rename numa ccode1
rename numb ccode2
order ccode1 ccode2 year rgdpca rgdpcb tottra tottrb popa popb
keep ccode1 ccode2 year rgdpca rgdpcb tottra tottrb popa popb
sort ccode1 ccode2 year
save "Other_files/gleditsch_dyad.dta", replace

*acra/b		Three letter acronym for state A/B	
*numa/b		Numeric id code for state A/B
*year		Year
*expab		Export A to B
*eabo		Export A to B origin code
*impab		Import A from B
*iabo		Import A from B origin code
*expba		Export B to A 		
*ebao		Export B to A origin code
*impba		Import B from A 
*ibao		Import B from A origin code
*popa		Population of A
*rgdpca/b	Real GDP per capita of A/B
*cgdpca/b	Current GDP per capita of A/B
*goa/b		Origin of GDP per capita estimate A/B
*tottra/b	Total trade for country A/B


****CIE data from Beck and Webb


clear

**"data-wber.xls" provided to Allan Dafoe by Thorsten Beck on June 23, 2012. 
*Another version of this file "beck_webb_original_data.xls" was found online at a link that is no longer live.

import excel "Other_files/data-wber.xls", sheet("panel") firstrow

*Count observations with lifepen coded
 count if lifedeer~=.
 count if lifepen~=.
 *334

*Count countries with lifepen coded
unique cc if lifepen~=.
*66

kountry cc, from(iso3c)
rename NAMES_STD country_name1
 
kountry cc, from(iso3c) to(cown)
rename _COWN_ ccode1

sort ccode1


keep ccode1 period lifepen lifedens lifedeer acli lifeexp gdppc income country_name1 

*rename cc cc1
rename period period1 
rename lifepen lifepen1
rename lifedens lifedens1
rename acli acli1
rename lifedeer lifedeer1
rename lifeexp lifeexp1
rename gdppc gdppc1
rename income income1
sort ccode1

*creating country-year data
expand 5

sort ccode1 period

by ccode1: gen year1=1960+_n
*Beck and Webb's excel file states that period 1 covers 1961-1965, period 2 1966-1970, etc...

sort ccode1 year1


save "beck_webb1.dta", replace

rename year1 year2
rename period1 period2
rename lifepen1 lifepen2
rename income1 income2
rename lifedens1 lifedens2
rename lifedeer1 lifedeer2
rename lifeexp1 lifeexp2
rename acli acli2
rename gdppc1 gdppc2
rename country_name1 country_name2
rename ccode1 ccode2

sort ccode2 year2
save "beck_webb2.dta", replace

clear
